package com.ebt.m.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.bumptech.glide.Glide;
import com.ebt.m.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
 * 单张图片显示
 */
public class ActSingleImgViewer extends AppCompatActivity {
    @BindView(R.id.image)
    PhotoView imgPicture;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.act_pic_viewer);
        ButterKnife.bind(this);
        init();
    }

    protected void init() {
        //新页面接收数据
        Bundle bundle = this.getIntent().getExtras();
        String url = bundle.getString("img_url");
        Glide.with(this).load(url).into(imgPicture);
        imgPicture.setDrawingCacheEnabled(true);
        imgPicture.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });
        imgPicture.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                finish();
            }
        });
    }


    public static void start(Context context, View view, String url) {
        Intent intent = new Intent(context, ActSingleImgViewer.class);
        intent.putExtra("img_url", url);
        ActivityCompat.startActivity(context, intent, ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context, view, "translate_view").toBundle());
    }
}
